package com.itheima.service.db;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;


@DubboService
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public Long save(User user) {
        //完善基本数据
        String md5pwd = SecureUtil.md5(user.getHxPassword());
        user.setPassword(md5pwd);
        user.setUpdated(new Date());
        user.setCreated(new Date());
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByPhone(String phone) {
        //编写条件
        QueryWrapper<User> qw=new QueryWrapper<>();
        qw.eq("mobile",phone);
        return userMapper.selectOne(qw);
    }
}
